<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="app.Usuario"
    import="app.Propiedad"
	import="util.Translator"%>
	 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<% //Language management
	Translator t = new Translator();
	String lang = request.getParameter("lang");
	Cookie c = null;

	Cookie [] cookies = request.getCookies();
	if (cookies != null)
		for (Cookie i : cookies)
			if (i.getName().equals("vlang")) {
				c = i;
				break;
			}
	
	if (c == null)
		c = new Cookie("vlang", "en");
			
   if (lang != null) {
	   t.setLanguage(lang);
	   c.setValue(lang);
	}
	else
		t.setLanguage(c.getValue());
 
   response.addCookie(c);
%>

<% 
	// User checking management
   session = request.getSession();
   Usuario u = (Usuario)session.getAttribute("vuser");
	
   //Properties bar
   Propiedad [] properties = null;
   
   /*Just testing
   u = new Usuario();
   u.setUsuario("peter");
   u.setTipo(Usuario.ADMIN);
   */
%>
<%

   if ((request.getParameter("st") != null) && (request.getParameter("st").equals("logout"))) {
		session.invalidate();
		u = null;
   }

%>
<html>
   <head>
      <link rel="stylesheet" type="text/css" href="css/homeStyle.css">
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title> <%=t.translate("Principal")%> </title>
   </head>
   
   <body>
      <% if (u != null) {%>
	  		<table class="mainTable">   
	        	<tr>
	        		<td>
	            	<a href="home.jsp">
	            		<img width="100px" height="50px" src="img/logo.jpg"/>
	            	</a>
	            </td>
	            
	            <td align="right" style="font-size:75%">
            		<table>
          				<tr>
          					<td> <%=t.translate("Identificado como")%> <b>(<%=u.getUsuario()%>)</b> </td>
          					<td>
          						<a href="home.jsp?st=logout">
          							<img width="87%" src=<%="img/" + t.translate("salir") + ".jpeg"%> />
          						</a>
          					</td>
          				</tr>  		
            		</table>
            	</td>
	         </tr>
	         
	         <tr> <th colspan="2"><hr color="#ffa200" width="100%" size="3px"/></th> </tr>
	         
	         <!-- buttons table -->
	         <tr>
	           <th colspan="2">
	              <table width="<%=(u.getTipo() == Usuario.ADMIN) ? 60 : 50%>>%">
	                 <tr>
	                    <td> <a href="home.jsp"> <img align="right" width="80%" src="<%="img/"+ t.translate("principal") + ".jpeg"%>"/> </a> </td>
	                    <td> <a href="profile.jsp"> <img align="right" width="80%" src="<%="img/"+ t.translate("perfil") + ".jpeg"%>"/> </a> </td>
	                    <td> <a href="properties.jsp"> <img align="right" width="80%" src="<%="img/"+ t.translate("inmuebles") + ".jpeg"%>"/> </a> </td>
	                    <%if (u.getTipo() == Usuario.ADMIN) {%>
	                       <td> <a href="users.jsp"> <img align="right" width="80%" src="<%="img/"+ t.translate("usuarios") + ".jpeg"%>"/> </a> </td>
	                    <%}%>
	                 </tr>
	              </table>
	           </th>
	         </tr>
				
				<!-- Body Home -->
				<tr>
					<th colspan="2">
						<table width="100%">
							<tr>
								<td>
									<table width="70%">
										<tr> <td> ??? </td></tr>
									</table>
								</td>
								
								<td style="padding-top: 20px; padding-bottom: 20px;"> 
									<table align="right" width="60%">
										<tr>
											<td align="right">
												<div class="scrollTable">
													<table width="100%" border="1" cellspacing="0" cellpadding="0" align="center">
														<%for (int i=0; i<10; i++) { %>
															<tr>
																<td>
																<table class="property">
																	<tr>
																		<td> 
																			<center> 
																				<a href="Search?header=1&id=<%=i%>"> <img width="70px" src="img/house.gif"></img> </a>
																			</center> 
																		</td>
																		<td>
																			<table>
																				<tr>
																					<td> <%=t.translate("Precio")%> </td>
																					<td align="center"> <tt> ~ € </tt> </td>
																				</tr>
																				<tr>
																					<td> <%=t.translate("Dimensiones")%> </td>
																					<td align="center"> <tt> ~ dimensi&oacute;n </tt> </td>
																				</tr>
																				<tr>
																					<td> <%=t.translate("Tipo de propiedad")%></td>
																					<td align="center"> <tt> ~ type </tt> </td>
																				</tr>
																			</table>
																		</td>
																	</tr>
																</table>
																</td>
															</tr>
														<%}%>
													</table>
												</div>
											</td>
										</tr>
										
										<tr>
											<td>
												<br><br>
												???
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</th>
				</tr>
	      </table>
	   <%} 
      else {%>
    	  	<jsp:forward page="index.jsp"/>
    	<%}%>
   </body>
   
</html>